package com.cwh.taskcenter.task.converter;

import com.alibaba.fastjson2.JSON;
import com.cwh.taskcenter.domain.task.model.Task;
import com.cwh.taskcenter.domain.task.model.TaskRule;
import com.cwh.taskcenter.task.dto.data.TaskDTO;
import com.cwh.taskcenter.task.dto.data.TaskInfoDTO;
import com.cwh.taskcenter.task.dto.data.TaskRuleDTO;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.Named;
import org.mapstruct.factory.Mappers;

/**
 * @author cwh
 */
@Mapper(componentModel = "spring")
public interface TaskConvert {

    TaskConvert INSTANCE = Mappers.getMapper(TaskConvert.class);

    @Mapping(source = "startTime", target = "startTime", dateFormat = "yyyy-MM-dd HH:mm:ss",
            conditionExpression = "java(taskDTO.getStartTime() != null && !taskDTO.getStartTime().isEmpty())")
    @Mapping(source = "endTime", target = "endTime", dateFormat = "yyyy-MM-dd HH:mm:ss",
            conditionExpression = "java(taskDTO.getEndTime() != null && !taskDTO.getEndTime().isEmpty())")
    Task toTask(TaskInfoDTO taskDTO);


    TaskRule toTaskRule(TaskRuleDTO taskRuleDTO);

}
